namespace hjc {

	export class AStarNode implements IPoolable {

		public static DFT_NODE_COST = 1;
		public static DFT_NODE_DATA = 1;
		public static DFT_DIAG_COST = 1.414;
		public static DFT_FLAG_BITS = 2;
		public col: number;			//列
		public row: number;			//行
		public x: number;			//中心点横坐标
		public y: number;			//中心点纵坐标
		public F: number;			//总代价(F=G+H)
		public G: number;			//当前代价		
		public H: number;			//预估代价
		public former: AStarNode;	//前节点
		public cost: number;		//路径代价
		public flag: number;		//标记

		public get walkable(): boolean { return this.cost > 0; }
		public get data(): number { return (this.flag ? Math.pow(2, AStarNode.DFT_FLAG_BITS) : 0) + this.cost; }
		public get vector2(): [number, number] { return [this.x, this.y]; }

		public init(col: number, row: number, x: number, y: number, data: number = AStarNode.DFT_NODE_DATA): AStarNode {
			this.col = col;
			this.row = row;
			this.x = x;
			this.y = y;
			this.cost = data & 3;
			this.flag = (data >> 2);
			this.F = this.G = this.H = 0;
			return this;
		}

		public update(former: AStarNode, H: number): AStarNode {
			this.former = former;
			this.G = this.former.G + this.cost;
			this.H = H;
			this.F = this.G + H;
			return this;
		}
	}
}